JComboBox
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
public class mani16 extends JApplet implements ItemListener
{
JLabel jl;
ImageIcon x1,x2,x3;
public void init()
{
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
JComboBox jc=new JComboBox();
jc.addItem("sowji");
jc.addItem("mani");
jc.addItem("sri");
jc.addItemListener(this);
cp.add(jc);
jl=new JLabel(new ImageIcon("1.gif"));
cp.add(jc);
setSize(200,200);
setVisible(true);
}
public void itemStateChanged(ItemEvent e)
{
String s=(String)e.getItem();
jl.setIcon(new ImageIcon(s+".gif"));
}
}
/*<applet code=mani16 width=200 height=300>
</applet>*/
.wap to print name age hs cen in JTextFields
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class mani15 extends JFrame implements ItemListener
{
JComboBox jc;
JTextField na,age,hs,cent;
public static void main(String args[])
{
new mani15();
}
mani15()
{
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
JComboBox jc=new JComboBox();
jc.addItem("sachin");
jc.addItem("shewag");
jc.addItemListener(this);
cp.add(jc);
na=new JTextField(20);
age=new JTextField(20);
hs=new JTextField(20);
cent=new JTextField(20);
cp.add(na);
cp.add(age);
cp.add(hs);
cp.add(cent);
setSize(200,200);
setVisible(true);
}
public void itemStateChanged(ItemEvent e)
{
String s=(String)e.getItem();
if(s.equals("sachin"))
{
na.setText("sachin");
age.setText("36");
hs.setText("255");
cent.setText("35");
}
else if(s.equals("shewag"))
{
na.setText("shewag");
age.setText("26");
hs.setText("155");
cent.setText("30");
}
}
}
wap on JTabbedPane
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
public class sri1 extends JApplet
{
public void init()
{
JTabbedPane jtp=new JTabbedPane();
jtp.addTab("cities",new citiesPanel());
jtp.addTab("colors",new colorsPanel());
jtp.addTab("flowers",new flowersPanel());
getContentPane().add(jtp);
}
}
class citiesPanel extends JPanel
{
public citiesPanel()
{
JButton b1=new JButton("hyd");
JButton b2=new JButton("delhi");
JButton b3=new JButton("tadanki");
JButton b4=new JButton("vuyyuru");
add(b1);
add(b2);
add(b3);
add(b4);
}
}
class colorsPanel extends JPanel
{
public colorsPanel()
{
JCheckBox b1=new JCheckBox("red");
JCheckBox b2=new JCheckBox("green");
JCheckBox b3=new JCheckBox("blue");
JCheckBox b4=new JCheckBox("yellow");
add(b1);
add(b2);
add(b3);
add(b4);
}
}
class flowersPanel extends JPanel
{
public flowersPanel()
{
JComboBox jcb=new JComboBox();
jcb.addItem("rose");
jcb.addItem("lilly");
add(jcb);
}
}
/*<applet code=sri1 width=200 height=300>
</applet>*/